package com.spa.interfaces.admin;

import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.CouponDTO;
import com.spa.application.dto.admin.CouponExchangeDTO;
import com.spa.application.dto.admin.CouponExchangeExportDTO;
import com.spa.application.dto.admin.CouponExportDTO;
import com.spa.application.query.admin.AdminCouponExchangeQuery;
import com.spa.application.query.admin.AdminCouponQuery;
import com.spa.application.service.admin.AdminCouponApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("admin/coupon")
public class AdminCouponController extends BaseController {

    @Autowired
    private AdminCouponApplicationService adminCouponApplicationService;

    @PostMapping("page")
    public ResponseMessage<PageResult<CouponExchangeDTO>> page(@RequestBody AdminCouponExchangeQuery query) {
        return responseHelper.success(adminCouponApplicationService.page(query));
    }

    @PostMapping("export")
    public void export(HttpServletResponse response, @RequestBody AdminCouponExchangeQuery query) throws Exception {
        List<CouponExchangeExportDTO> list = adminCouponApplicationService.list(query);
        exportQueryResult(response, list, "团购券兑换记录", "团购券兑换记录", CouponExchangeExportDTO.class);
    }

    @PostMapping("use/page")
    public ResponseMessage<PageResult<CouponDTO>> usePage(@RequestBody AdminCouponQuery query) {
        return responseHelper.success(adminCouponApplicationService.pageCoupon(query));
    }

    @PostMapping("use/export")
    public void useExport(HttpServletResponse response, @RequestBody AdminCouponQuery query) throws Exception {
        List<CouponExportDTO> list = adminCouponApplicationService.listCoupon(query);
        exportQueryResult(response, list, "团购券兑换记录", "团购券兑换记录", CouponExportDTO.class);
    }

}
